<template>
  <!-- 修改窗口 -->
  <a-modal v-model:visible="visible2" title="修改员工信息" @ok="execUpd">
    <a-form
      :model="updObj"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-item label="员工号">
        <a-input v-model:value="updObj.st_id" disabled />
      </a-form-item>
      <a-form-item label="姓名">
        <a-input v-model:value="updObj.st_name" />
      </a-form-item>
      <a-form-item label="性别">
        <a-radio-group v-model:value="updObj.st_sex">
          <a-radio :value="true">男</a-radio>
          <a-radio :value="false">女</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="出生日期">
        <a-input v-model:value="updObj.st_birth" disabled />
      </a-form-item>

      <a-form-item label="职位">
        <div>
          <a-radio-group
            size="small"
            v-model:value="updObj.ro_id"
            button-style="solid"
          >
            <a-radio-button value="1200">销售管理员</a-radio-button>
            <a-radio-button value="1300">库存管理员</a-radio-button>
            <a-radio-button value="1400">收银员</a-radio-button>
          </a-radio-group>
        </div>
      </a-form-item>
      <a-form-item label="工作状态">
        <a-radio-group v-model:value="updObj.st_state">
          <a-radio :value="true">在职</a-radio>
          <a-radio :value="false">请假</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="月薪">
        <a-input v-model:value="updObj.st_salary" />
      </a-form-item>
      <a-form-item label="电话">
        <a-input v-model:value="updObj.st_tel" />
      </a-form-item>
      <a-form-item label="住址">
        <a-input v-model:value="updObj.st_address" />
      </a-form-item>
      <a-form-item label="备注">
        <a-textarea v-model:value="updObj.st_remark" :rows="3" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { ref, reactive } from "vue";
import { put, tip } from "@/common";

export default {
  // emit是一个函数，用于子组件向父组件发射事件
  setup(props, { emit }) {
    //修改
    const updObj = reactive({
      st_id: "",
      st_name: "",
      st_sex: "",
      st_birth: "",
      st_tel: "",
      st_address: "",
      st_state: "",
      st_remark: "",
      ro_id: 0,
      st_salary: "",
    });
    const visible2 = ref(false);
    const openUpd = (st) => {
      updObj.st_id = st.st_id;
      updObj.st_name = st.st_name;
      updObj.ro_id = st.ro_id;
      updObj.st_sex = st.st_sex;
      updObj.st_birth = st.st_birth;
      updObj.st_tel = st.st_tel;
      updObj.st_address = st.st_address;
      updObj.st_state = st.st_state;
      updObj.st_remark = st.st_remark;
      updObj.st_salary = st.st_salary;
      //打开窗口
      visible2.value = true;
    };
    const execUpd = () => {
      //执行修改
      put("/branch/staff", updObj).then((res) => {
        updObj.st_id = "";
        updObj.st_name = "";
        updObj.ro_id = "";
        updObj.st_sex = "";
        updObj.st_birth = "";
        updObj.st_tel = "";
        updObj.st_address = "";
        updObj.st_state = "";
        updObj.st_remark = "";
        updObj.st_salary = "";
        visible2.value = false;
        tip.success("修改员工信息成功！");
        //通知父组件执行更新页面的方法
        emit("yes"); //向父组件发射一个名称为yes的事件，此事件表示新增完成
      });
    };

    return {
      //声明数据和方法
      updObj,
      visible2,
      openUpd,
      execUpd,
    };
  },
};
</script>

<style scoped>
</style>